package it.hopeless.jee6.persistence;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class PersistenceService {

    @PersistenceContext(name = "jee6")
    private EntityManager entityManager;

    private final static Logger logger = LoggerFactory.getLogger(PersistenceService.class);

    public void createBook() {
        logger.info("Creating book");
        Book book = new Book(1L, "title", Genre.THRILLER, 23.0);
        entityManager.persist(book);
    }

    public Book deleteBook() {
        logger.info("Deleting book");
        return entityManager.find(Book.class, 1L);
    }

}